﻿using System.Collections;
using System.Collections.Generic;

namespace Acoris.Markdown
{
    /// <summary>
    /// 表示一个AML项的值
    /// </summary>
    internal class AMLValue:IEnumerable<AMLValuePair>
    {
        List<AMLValuePair> m_collection;

        /// <summary>
        /// 
        /// </summary>
        public AMLValue() {
            m_collection = new List<AMLValuePair>();
        }

        internal void GetValue(string value)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="collection"></param>
        public AMLValue(IEnumerable<AMLValuePair> collection)
        {
            m_collection = new List<AMLValuePair>(collection);
        }

        /// <summary>
        /// 返回当前AML内容的键值对集合
        /// </summary>
        public IList<AMLValuePair> Values {
            get { return m_collection; }
        }

        /// <summary>
        /// 返回用于当前对象的枚举数
        /// </summary>
        /// <returns>返回用于当前对象的枚举数</returns>
        public IEnumerator<AMLValuePair> GetEnumerator()
        {
            return m_collection.GetEnumerator();
        }

        /// <summary>
        /// 返回用于当前对象的枚举数
        /// </summary>
        /// <returns>返回用于当前对象的枚举数</returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return m_collection.GetEnumerator();
        }

        /// <summary>
        /// 获取或设置指定索引位置的元素
        /// </summary>
        /// <param name="index">指定的索引位置</param>
        /// <returns>返回指定索引位置的元素</returns>
        public AMLValuePair this[int index]
        {
            get { return m_collection[index]; }
            set { m_collection[index] = value; }
        }

        /// <summary>
        /// 获取当前对象的哈希值
        /// </summary>
        /// <returns>返回当前对象的哈希值</returns>
        public override int GetHashCode()
        {
            return m_collection.GetHashCode() ^ base.GetHashCode();
        }

        /// <summary>
        /// 比较两个对象的等价性
        /// </summary>
        /// <param name="obj">要比较的对象</param>
        /// <returns>如果两个对象等价性一直则返回true，否则返回false</returns>
        public override bool Equals(object obj)
        {
            return obj.Equals(this);            
        }

        /// <summary>
        /// 获取当前对象中集合的元素个数
        /// </summary>
        public int Count
        {
            get { return m_collection.Count; }
        }

        /// <summary>
        /// 获取与当前对象等价的字符串形式
        /// </summary>
        /// <returns>返回与当前对象等价的字符串形式</returns>
        public override string ToString()
        {
            return $"<value,count:{m_collection.Count}>";
        }

        public static bool operator == (AMLValue x,AMLValue y)
        {
            return x.GetHashCode() == y.GetHashCode();
        }

        public static bool operator !=(AMLValue x,AMLValue y)
        {
            return x.GetHashCode() != y.GetHashCode();
        }
    }
}
